#include <QDebug>
#include <QEvent>
#include <QPainter>
#include <QPaintEvent>
#include <QPainterPath>

#include "vpushbutton.h"
#include "vlineedit.h" 
#include "vloginwidget.h"
#include "vswitchinterfacebutton.h"
#include "verrorpromptlabel.h"

VLoginWidget::VLoginWidget(QWidget* parent)
    :QWidget(parent)
    , m_pButtonLogin(new VPushButton(this))
    , m_pLineEditAccount(new VLineEdit(this))
    , m_pLineEditPassword(new VLineEdit(this))
    , m_pButtonSwitchLoginWidget(new VSwitchInterfaceButton(this))
    , m_pLabelErrorPrompt(new VErrorPromptLabel(this))
    , m_pButtonSwitchReviseWidget(new VSwitchInterfaceButton(this))
{
    resize(280, 355);
    move(0, 25);
    initLoginButton();//初始化按钮
    initLineEdit();//初始化输入框
    initConnect();//初始化信号与槽链接
}

void VLoginWidget::initLoginButton()
{
    m_pButtonSwitchReviseWidget->setText("忘记密码");
    m_pButtonSwitchReviseWidget->move(145, 290);
    m_pButtonSwitchLoginWidget->setText("注册账号");
    m_pButtonSwitchLoginWidget->move(75, 290);
    m_pButtonLogin->setText("进入微信");
}
void VLoginWidget::initConnect()
{
    connect(m_pButtonLogin, &VPushButton::released, this, &VLoginWidget::onLoginButtonReleased); 
    //登录按钮发送，登录按钮获取，调用onLoginButtonReleased函数
}

void VLoginWidget::onLineEditAccountFormatError(QSet<ERRORTYPE>errorExist)
{
    m_pLabelErrorPrompt->setErrorPrompt(errorExist);
}

VLoginWidget::~VLoginWidget()
{}

void VLoginWidget::onLoginButtonReleased() //当登录按钮被释放后获取lineedit的账号密码...loginwidget类内，获取m_pLineEditAccount->text()
{
    
    auto account = m_pLineEditAccount->text();
    auto password = m_pLineEditPassword->text();
    qDebug() << account << "    " << password;

    //h:signals yanzheng(acc,pass)//设置信号，异步验证

    //emit yanzheng;

    //connect(yanzheng,yanzhengmima); 
   /*bool result = yanzhengmima(account, password)//调用数据库接口

        if (result)
        {

        }
        else
        {

        }*/


}


void VLoginWidget::initLineEdit()
{
    m_pLineEditAccount->move(30, 81);
    m_pLineEditPassword->move(30, 135);
    m_pLineEditAccount->setPlaceholderText("输入微信账号");
    m_pLineEditPassword->setPlaceholderText("输入微信密码");

    m_pLineEditAccount->setMode(ECHOMODE::LOGIN_ACCOUNT);
    m_pLineEditPassword->setMode(ECHOMODE::LOGIN_PASSWORD);
}

